//
//  FFWalletTradeRecordCell.m
//  LLWallet
//
//  Created by tt on 2020/9/7.
//

#import "FFWalletTradeRecordCell.h"

@implementation FFWalletTradeRecordModel


- (Class)cell {
    return FFWalletTradeRecordCell.class;
}

@end

@interface FFWalletTradeRecordCell ()

@property(nonatomic,strong) FFWalletTradeRecordModel *model;

@property(nonatomic,strong) UILabel *titleLbl; // 标题
@property(nonatomic,strong) UILabel *timeLbl; // 时间
@property(nonatomic,strong) UILabel *amountLbl; // 金额
@property(nonatomic,strong) UILabel *balanceLbl; // 余额


@end

@implementation FFWalletTradeRecordCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 80.0f);
}

- (void)setupUI {
    [super setupUI];
    [self.contentView addSubview:self.titleLbl];
    [self.contentView addSubview:self.timeLbl];
    [self.contentView addSubview:self.amountLbl];
    [self.contentView addSubview:self.balanceLbl];
}

- (UILabel *)titleLbl {
    if(!_titleLbl) {
        _titleLbl = [[UILabel alloc] init];
        [_titleLbl setFont:[[WKApp shared].config appFontOfSize:16.0f]];
    }
    return _titleLbl;
}

- (UILabel *)timeLbl {
    if(!_timeLbl) {
         _timeLbl = [[UILabel alloc] init];
        [_timeLbl setFont:[[WKApp shared].config appFontOfSize:14.0f]];
        [_timeLbl setTextColor:[WKApp shared].config.tipColor];
    }
    return _timeLbl;
}
- (UILabel *)amountLbl {
    if(!_amountLbl) {
         _amountLbl = [[UILabel alloc] init];
        [_amountLbl setFont:[[WKApp shared].config appFontOfSizeSemibold:18.0f]];
    }
    return _amountLbl;
}
- (UILabel *)balanceLbl {
    if(!_balanceLbl) {
         _balanceLbl = [[UILabel alloc] init];
        [_balanceLbl setFont:[[WKApp shared].config appFontOfSize:14.0f]];
        [_balanceLbl setTextColor:[WKApp shared].config.tipColor];
    }
    return _balanceLbl;
}


- (void)refresh:(FFWalletTradeRecordModel*)cellModel {
    [super refresh:cellModel];
    self.model = cellModel;
    self.titleLbl.text = cellModel.title;
    self.timeLbl.text = cellModel.time;
    self.balanceLbl.text = [NSString stringWithFormat:LLang(@"余额 %@"),[WKMoneyUtil penny2YuanFormat:cellModel.balance]];
    if(cellModel.amount.intValue < 0) {
         self.amountLbl.text = [WKMoneyUtil penny2YuanFormat:cellModel.amount];
        [self.amountLbl setTextColor:[UIColor blackColor]];
    }else {
        self.amountLbl.text = [NSString stringWithFormat:@"+%@",[WKMoneyUtil penny2YuanFormat:cellModel.amount]];
        [self.amountLbl setTextColor:[UIColor colorWithRed:229.0f/255.0f green:177.0f/255.0f blue:71.0f/255.0f alpha:1.0f]];
    }
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.titleLbl.lim_left = 15.0f;
    self.titleLbl.lim_top = 10.0f;
    self.titleLbl.lim_width = self.lim_width - 80.0f;
    self.titleLbl.lim_height = 18.0f;
    
    self.timeLbl.lim_top = self.titleLbl.lim_bottom + 10.0f;
    self.timeLbl.lim_left = self.titleLbl.lim_left;
    self.timeLbl.lim_height = 16.0f;
    self.timeLbl.lim_width = 200.0f;
    
    [self.amountLbl sizeToFit];
    self.amountLbl.lim_top = self.titleLbl.lim_top;
    self.amountLbl.lim_height = 18.0f;
    self.amountLbl.lim_left = self.lim_width - self.amountLbl.lim_width - 15.0f;
    
    [self.balanceLbl sizeToFit];
    self.balanceLbl.lim_top = self.amountLbl.lim_bottom + 10.0f;
    self.balanceLbl.lim_height = 16.0f;
    self.balanceLbl.lim_left = self.lim_width - self.balanceLbl.lim_width - 15.0f;
  
}


@end
